package com.e3.web.widget.client;

import java.util.HashMap;
import java.util.Map;

import com.e3.web.core.model.SuperModel;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

public class MyGridHelper {

	public static <D extends SuperModel> GridCellRenderer<D> createListCellRender(final String fName,Object[] codes,String[] dispNames){
		Map<String,String> valueMap = new HashMap<String, String>();
		for (int i=0;i<codes.length;i++) {
			Object code = codes[i];
			String dispName = dispNames[i];
			valueMap.put(code.toString(), dispName);
		}
		final MyListCellRenderer<Grid<D>> listRender = new MyListCellRenderer<Grid<D>>(valueMap);
	    GridCellRenderer<D> cellRenderer = new GridCellRenderer<D>() {
			public Object render(D model, String property,
					ColumnData config, int rowIndex, int colIndex,
					ListStore<D> store, Grid<D> grid) {
				return listRender.render(null, property, model.get(fName));
			}
		};
		return cellRenderer;
	}
}
